<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link href="CSS/style.css" rel="stylesheet" />
    
</head>
<body background="pic/04.jpg" style="background-repeat: no-repeat;
background-size: 100% 100%; background-attachment: fixed;">
    <div  class="Box">
        <form>
            <div class="welcom">欢迎注册</div>
            <div class="yhm">
                用户名：<input id = "username" type = "text" value = "" maxlength="10"><br>
            </div>
            <div class="nl">
                密码：<input id = "password" type = "text" value = "" maxlength="10">
            </div>
            <div class="dz">
              <div class="zc">
                <input id="box2" type = "button" value = "注册" onclick="send_post()">
             </div>
            </div>
        </form>
    </div>
    <script >
        var baseUrl = "http://qlapi.sylu.edu.cn/mock/67";
        function send_post() 
        {
          var der = null;
          let username=document.getElementById("username").value;
          let password=document.getElementById("password").value;
          _value={
            username: username,
            password: password,
          }
          try 
          {
            der = new XMLHttpRequest();
          } 
          catch (error) 
          {
            der = new ActiveXObject("Microsoft.XMLHTTP");
          }
          der.open("post", `${baseUrl}/register`, true);
          der.setRequestHeader("Content-Type", "application/json");
          der.send(JSON.stringify(_value));
          der.onreadystatechange = function () 
          {
            if (der.readyState == 4) 
            {
              if (der.status == 200) 
              {
                const seg = der.responseText; 
                console.log(seg);
                alert("注册成功！" );
                window.location.href="post登录页面.html";
              } 
              else 
              {
                alert("Error:" + der.status);
              }
            }
          }
        }
    </script>
</body>
</html>